import {
  reqCategoryListData,
  reqGetBannerListData,
  reqGetFloorsListData,
} from "../../api";
const state = {
  categoryList: [],
  bannerList: [],
  floorsList: []
};
const actions = {
  // 1. 获取三级分数数据
  async getCategoryListData(context) {
    const result = await reqCategoryListData();
    if (result.code === 200) {
      // 如果成功 则提交给mutations中的方法
      context.commit("GET_CATEGORY_LIST_DATA", result);
    } else {
      console.log(result.message);
    }
  },
  // 获取轮播数据
  async reqGetBannerListData({ commit }) {
    const result = await reqGetBannerListData();
    if (result.code === 200) {
      commit("SAVA_BANNER_LIST_DATA", result.data);
    } else {
      console.log(result.message);
    }
  },
  // 获取floor数据
  async getFloorsListData({ commit }) {
    const result = await reqGetFloorsListData();
    console.log(result);
    if (result.code === 200) {
      commit("SAVE_FLOORS_LIST_DATA", result.data);
    } else {
      console.log(result.message);
    }
  },
};
const mutations = {
  GET_CATEGORY_LIST_DATA(state, payload) {
    // console.log(12,payload);
    state.categoryList = payload.data;
  },
  SAVA_BANNER_LIST_DATA(state, bannerList) {
    state.bannerList = bannerList;
  },
  SAVE_FLOORS_LIST_DATA(state, floorsList) {
    state.floorsList = floorsList;
  },
};
const getters = {};

// 4. 导出对象
export default {
  namespaced: true, // 既然是分模块进行开发了,一定要开启命名空间
  state,
  actions,
  mutations,
  getters,
};
